local skel = fk.CreateSkill {
  name = "rmt__wanla",
  tags = {Skill.Limited},
}

Fk:loadTranslationTable{
  ["rmt__wanla"] = "完。",
  [":rmt__wanla"] = "限定技，其他角色结束阶段，若你的【嘭！】张数大于其手牌数与体力值之和，你可以对其使用所有【嘭！】。",

  ["#rmt__wanla-ask"] = "完：你可以对 %src 使用所有【嘭！】",

  ["$rmt__wanla1"] = "",
  ["$rmt__wanla2"] = "",
}

skel:addEffect(fk.EventPhaseStart, {
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and not player:isKongcheng()
    and player:usedSkillTimes(skel.name, Player.HistoryGame) == 0
    and target ~= player and target.phase == Player.Finish and not target.dead then
      local num = #table.filter(player.player_cards[Player.Hand], function(id)
        return Fk:getCardById(id).name == "peng"
      end)
      return num > 0 and num > (target.hp + target:getHandcardNum())
    end
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#rmt__wanla-ask:"..target.id}) then
      event:setCostData(self, {tos = {target}})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:filterHandcards()
    while not player.dead and not target.dead do
      local card
      for _, id in ipairs(player.player_cards[Player.Hand]) do
        local c = Fk:getCardById(id)
        if c.name == "peng" and not player:prohibitUse(c) and not player:isProhibited(target, c) then
          card = c
          break
        end
      end
      if not card then break end
      room:useCard{from = player, tos = {target}, card = card, extraUse = true}
    end
  end,
})

return skel
